<extend name="base"/>

<block name="css">

</block>

<block name="main">
    <div class="set-box">
        <div class="sb-nr">
            <label class="sbn-l">收货人：</label>
            <input placeholder="请输入收货人姓名" placeholder-style="color:#aaa;" class="sbn-wb username" value="{$data.username}"></input>
            <div class="clear"></div>
        </div>

        <div class="sb-nr">
            <label class="sbn-l">联系方式：</label>
            <input placeholder="请输入手机号码" placeholder-style="color:#aaa;" class="sbn-wb mobile" value="{$data.mobile}"></input>
            <div class="clear"></div>
        </div>

        <div class="sb-nr">
            <label class="sbn-l">所在地区：</label>

            <picker class="weui-cell__bd">
                <input class="weui-input region" id="start" type="text" style="padding-top: 0.75rem; width: calc(100% - 1rem);font-size: 0.7rem;" value="{:I('id') == 0 ? '北京市 北京市 东城区' : $data['region_desc']}" readonly></input>
                <img src='__HELPER_IMG__/icon_down.png'></img>
                <div class="clear"></div>
            </picker>

            <div class="clear"></div>
        </div>

        <div class="sb-nr">
            <label class="sbn-l">详细地址：</label>
            <input placeholder="请输入详细地址" placeholder-style="color:#aaa;" class="sbn-wb address" value="{$data.address}"></input>
            <div class="clear"></div>
        </div>

        <div class="sb-nr">
            <label class="sbn-l">设为默认：</label>

            <picker class="weui-cell__bd">
                <input class="weui-input is_default" id="default" style="padding-top: 0.75rem;width: calc(100% - 1rem); font-size: 0.7rem;" type="text" value="{$data.is_default}" readonly>
                <img src='__HELPER_IMG__/icon_down.png'></img>
                <div class="clear"></div>
            </picker>

            <div class="clear"></div>
        </div>

        <button class="sb-btn" onclick="submit()">保存</button>
    </div>
</block>

<block name="js">
    <script>
        $("#start").cityPicker({
            title: "所在地区"
        });

        $("#default").picker({
            title: "设为默认",
            cols: [
                {
                    textAlign: 'center',
                    values: ['是', '否']
                }
            ]
        });

        function submit()
        {
            var id = "{:I('id')}";

            var url = id > 0 ? "/Apis/editAddress" : "/Apis/addAddress";

            var uid = "{$Think.session.uid}";
            var username = $('.username').val();
            var mobile = $('.mobile').val();
            var region = $('.region').val().split(' ');
            var address = $('.address').val();
            var is_default = $('.is_default').val() == '是' ? 1 : 0;

            $.showLoading('请稍等');

            post_ajax(url, {
                id: id,
                uid: uid,
                username: username,
                mobile: mobile,
                province: region[0],
                city: region[1],
                area: region[2],
                address: address,
                is_default: is_default
            }, function (res){
                layer.msg(res.msg)
                if(res.result == 1){
                    setTimeout(function(){
                        history.go(-1);
                    },1000)
                }
            })


        }
    </script>
</block>
